<?php 	header('Content-Type: text/html; charset=utf-8;');
?><html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
		<title>Xendri UnitTests Listing</title>
	</head>
	<body style='margin: 0; padding: 0; background: #444;'>
<div style='width:100%;height: 25%; overflow: auto; display: block; background: #eee;'><ul>
<?php
	require_once 'PHPUnit.php';

	error_reporting(E_ALL);
	
		
	// processing `./dev` directory
	if ($incdir = opendir('./dev'))
	{
		while (false !== ($tests[] = readdir($incdir))){}
	}
	
		sort($tests, SORT_ASC);
		foreach ($tests as $test) {
			if (in_array($test, array('.', '..'))) {
				continue;
			}
		
			if (preg_match(">test_[^\\.]+\\.php>", $test)) 
			{
				$test = str_replace('.php', '', $test);
				echo "<li><a href='?file=$test'>$test</a></li>";
			}
		}
		
	// запускаем Xendri в режиме Unit testing
	if (@$_GET['file']) {
		// Default library directory with end slash!!!
		$GLOBALS['libdir'] = 'lib/';
		// Default config directory with end slash!!!
		$GLOBALS['cfgdir'] = 'etc/';
		
		error_reporting(E_ALL);
		ini_set('display_errors', '1');
		
		// session must start in Auth class
		
		// processing `/inc` directory
		if ($incdir = opendir('./inc'))
		{
			while (false !== ($files[] = readdir($incdir))){}
		}
		
		
		sort($files, SORT_ASC);
		foreach ($files as $file) {
			if (in_array($file, array('.', '..'))) {
				continue;
			}
		
			if (strstr($file, 'php')) 
			{
				if (file_exists('dev/inc/'.$file)) {
					$file = 'dev/inc/'.$file;
				} else {
					$file = 'inc/'.$file;
				}
				if (class_exists('Log')) {
					if (Log::targeted()) {
						Log::warning('DEVINIT: Including file: '.$file);
					}
				}
				
				include ($file);
			}
		}
	}
		
?>
</ul>
</div>
<div style='width:96%; max-width: 96%; margin-top: 2%; margin-left: 2%; background-color: #444; color: white;'>
<?php if (@$_GET['file']) {
        error_reporting(E_ALL);
	ini_set('display_errors', '1');
        include 'dev/'.$_GET['file'].'.php';
	$suite = new PHPUnit_TestSuite($_GET['file']);
	$result = PHPUnit::run($suite);
	
	echo str_replace("\t", '&nbsp;&nbsp;&nbsp;&nbsp;', str_replace("\n","<br/>", $result->toString()));
}
?>
</div>
</body>